package com.hunan.api.catv.service.biz.umeng;

import com.google.gson.JsonObject;
import com.hunan.api.catv.common.Constants;
import com.hunan.api.catv.common.ConstantsMsg;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.service.ResultService;
import com.hunan.api.catv.service.biz.cache.CacheBiz;
import com.hunan.api.catv.service.impl.umeng.UmengService;
import com.hunan.api.catv.utils.GsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class UmengBiz extends ResultService {

    @Autowired
    UmengService umengService;

    @Autowired
    CacheBiz cacheBiz;

    public ServiceResult getAllAppData() {
        JsonObject umengConf = GsonUtils.fromJson(cacheBiz.getSystemDict(Constants.umeng_conf), JsonObject.class);
        if (!ObjectUtils.isEmpty(umengConf)) {
            String apiKey = umengConf.get("apiKey").getAsString();
            String apiSecurity = umengConf.get("apiSecurity").getAsString();
            String host = umengConf.get("host").getAsString();
            String data = umengService.umengUappGetAllAppData(apiKey, apiSecurity, host);
            if (!ObjectUtils.isEmpty(data)) {
                return buildOK(GsonUtils.fromJson(data, JsonObject.class));
            }
        }
        return buildFail(ConstantsMsg.umeng_getAll_fail);

    }
}
